﻿using DevExpress.Utils.Win;
using DevExpress.XtraEditors.Popup;
using DevExpress.XtraGrid.Demos.util;
using DevExpress.XtraGrid.Editors;
using DevExpress.XtraLayout;
using DevExpress.XtraReports.UI;
using DXApplicationTangche.Const;
using DXApplicationTangche.DTO;
using DXApplicationTangche.report;
using DXApplicationTangche.UC.下单MTO;
using DXApplicationTangche.UC.下单MTO.Service;
using DXApplicationTangche.UC.客户CRM.Service;
using DXApplicationTangche.UC.成品出库单.service;
using DXApplicationTangche.UC.成衣进销存.service;
using DXApplicationTangche.UC.订单.service;
using DXApplicationTangche.UC.订单一览新.订单预览新;
using DXApplicationTangche.UC.订单一览新.订单预览新.model;
using DXApplicationTangche.UC.订单一览新.订单预览新.service;
using DXApplicationTangche.UC.货号管理.service;
using DXApplicationTangche.UC.销售记录.service;
using DXApplicationTangche.UC.门店下单.DTO;
using DXApplicationTangche.UC.门店下单.service;
using DXApplicationTangche.UC.门店出入库.Service;
using mendian;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace DXApplicationTangche.UC.订单一览新.销售确认单
{
    public partial class Form销售确认下单 : DevExpress.XtraEditors.XtraForm
    {
        #region 销售出库
        //private StockInOutTitleDTO saleStockInOutTitleDTO = new StockInOutTitleDTO();
        private List<StockInOutDetailDTO> saleStockInOutDetailDTOs = new List<StockInOutDetailDTO>();
        private StockInOutDetailDTO saleStockInOutDetailDTO = new StockInOutDetailDTO();
        private String saleSessionId;
        #endregion
        #region 客套
        public OrderCommitDTO返回 orderCommitDTO返回 = new OrderCommitDTO返回();
        #endregion
        #region 定制
        private List<CustomerMadeSaleConfirmDTO> customerMadeSaleConfirmDTOs = new List<CustomerMadeSaleConfirmDTO>();
        #endregion

        private 下单Model saleModel;
        private String barCode { get; set; }
        #region 销售组织及人员
        private VerificationVO verificationVO = new VerificationVO();
        #endregion
        private String mobile { get; set; }
        #region 整体调价相关
        private String findStoreId { get; set; }
        private String findStoreName { get; set; }
        private String findAssistantId { get; set; }
        private String findAssistantName { get; set; }
        #endregion

        private String materialCode { get; set; }
        private String materialNameCn { get; set; }
        private String dateTimeStr { get; set; }
        private Double finalPrice { get; set; }
        private Double changePrice { get; set; }
        private CustomerPDTO customerPDTO = new CustomerPDTO();
        private CustomerDailyDiscountDTO customerDailyDiscountDTO = new CustomerDailyDiscountDTO();
        private CustomerMadeSaleConfirmDTO customerMadeSaleConfirmDTO;
        private CustomerSaleOrderReportDTO customerSaleOrderReportDTO = new CustomerSaleOrderReportDTO();
        private 订单预览新Model model;

        #region 构造函数
        public Form销售确认下单()
        {
            InitializeComponent();
            this.searchLookUpEdit店铺.Properties.DataSource = 销售记录Service.get店铺();
            this.searchLookUpEdit销售员.Properties.DataSource = 销售确认Service.get销售员带助记码();
            this.searchLookUpEdit定制选择参考成衣.Properties.DataSource = 货号管理Service.getSaleStyleSampleWithDateTime(0, 5000);
            this.searchLookUpEdit选择客套参考成衣.Properties.DataSource = 货号管理Service.getSaleStyleSampleWithDateTime(0, 5000);
            this.searchLookUpEdit面料.Properties.DataSource = MTO订单Service.getMaterialOrderIndexAll();
            this.config读取店铺();
            this.searchLookUpEdit店铺1.Properties.DataSource = 销售记录Service.get店铺();
            this.searchLookUpEdit销售员1.Properties.DataSource = 销售记录Service.get销售员();
            this.searchLookUpEdit成单人.Properties.DataSource = 销售记录Service.get销售员();
        }

        public class 下单Model
        {
            public String refBarcode { get; set; }
            public String mobile { get; set; }
            public String styleSizeCd { get; set; }
            public String storeId { get; set; }
            public String assistantId { get; set; }
            public String materialCode { get; set; }

            public 下单Model(Form销售确认下单 form, String saleType)
            {
                if (saleType.Equals("定制下单"))
                {
                    this.refBarcode = form.textBox定制扫码.Text;
                    this.mobile = form.textBox联系电话.Text;
                    this.styleSizeCd = form.comboBox定制尺码.Text;
                    this.storeId = form.verificationVO.storeId;
                    this.assistantId = form.verificationVO.assistantId;
                    this.materialCode = form.textBox定制面料号.Text;
                }
            }

            public void verify定制下单()
            {
                if (String.IsNullOrWhiteSpace(this.refBarcode))
                    throw new Exception("请扫描成衣码");
                if (String.IsNullOrWhiteSpace(this.mobile))
                    throw new Exception("请选择客户");
                if (String.IsNullOrWhiteSpace(this.styleSizeCd))
                    throw new Exception("请选择尺码");
                if (String.IsNullOrWhiteSpace(this.storeId))
                    throw new Exception("请选择门店");
                if (String.IsNullOrWhiteSpace(this.assistantId))
                    throw new Exception("请选择销售");
                if (String.IsNullOrWhiteSpace(this.materialCode))
                    throw new Exception("请选择款式");
            }
        }
        private void config读取店铺()
        {
            if (System.IO.File.Exists(@"xml\config店铺.xml"))
            {
                DTO销售表头 dTO店铺 = DealXML.XMLFlieToObject<DTO销售表头>(@"xml\config店铺.xml", Encoding.UTF8);
                this.verificationVO.buildStore(dTO店铺.id, dTO店铺.name);
                this.searchLookUpEdit店铺.Text = this.verificationVO.storeName;
                this.searchLookUpEdit店铺.Enabled = false;
            }
        }
        #endregion

        #region 事件
        #region 01 searchLookUp事件
        #region 下单选店铺
        private void searchLookUpEdit店铺_Popup(object sender, EventArgs e)
        {
            PopupSearchLookUpEditForm form = (sender as IPopupControl).PopupWindow as PopupSearchLookUpEditForm;
            SearchEditLookUpPopup popup = form.Controls.OfType<SearchEditLookUpPopup>().FirstOrDefault();
            LayoutControl layout = popup.Controls.OfType<LayoutControl>().FirstOrDefault();
            //如果窗体内空间没有确认按钮，则自定义确认simplebutton，取消simplebutton，选中结果label
            if (layout.Controls.OfType<Control>().Where(ct => ct.Name == "btOK").FirstOrDefault() == null)
            {
                //得到空的空间
                EmptySpaceItem a = layout.Items.Where(it => it.TypeName == "EmptySpaceItem").FirstOrDefault() as EmptySpaceItem;

                //得到取消按钮，重写点击事件
                Control clearBtn = layout.Controls.OfType<Control>().Where(ct => ct.Name == "btClear").FirstOrDefault();
                LayoutControlItem clearLCI = (LayoutControlItem)layout.GetItemByControl(clearBtn);
                clearBtn.Click += clear店铺Btn_Click;

                //添加一个simplebutton控件(确认按钮)
                LayoutControlItem myLCI = (LayoutControlItem)clearLCI.Owner.CreateLayoutItem(clearLCI.Parent);
                myLCI.TextVisible = false;
            }
        }
        private void searchLookUpEdit店铺View_Click(object sender, EventArgs e)
        {
            int[] a = this.searchLookUpEdit店铺.Properties.View.GetSelectedRows();
            if (a.Length > 0)
            {
                foreach (int rowHandle in a)
                {
                    String storeId = this.searchLookUpEdit店铺.Properties.View.GetRowCellValue(rowHandle, "id").ToString();
                    String storeName = this.searchLookUpEdit店铺.Properties.View.GetRowCellValue(rowHandle, "name").ToString();
                    this.verificationVO.buildStore(storeId, storeName);
                    if (!System.IO.File.Exists(@"xml\config店铺.xml"))
                    {
                        DealXML.ObjectToXMLFile(new DTO销售表头(this.verificationVO.storeId, this.verificationVO.storeName), @"xml\config店铺.xml", Encoding.UTF8);
                        this.config读取店铺();
                    }
                }
            }
        }

        /// <summary>
        /// 清除按钮事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void clear店铺Btn_Click(object sender, EventArgs e)
        {
            this.searchLookUpEdit店铺.ToolTip = null;
            searchLookUpEdit店铺.EditValue = null;
        }
        private void searchLookUpEdit店铺_CustomDisplayText(object sender, DevExpress.XtraEditors.Controls.CustomDisplayTextEventArgs e)
        {
            if (null != e.Value)
                e.DisplayText = this.verificationVO.storeName;
        }

        private void simpleButton重选店铺_Click(object sender, EventArgs e)
        {
            if (System.IO.File.Exists(@"xml\config店铺.xml"))
            {
                File.Delete(@"xml\config店铺.xml");
                this.searchLookUpEdit店铺.Enabled = true;
                this.verificationVO.clearStore();
                this.searchLookUpEdit店铺.Text = "";
            }
        }
        #endregion
        #region 下单选销售员
        private void searchLookUpEdit销售员_Popup(object sender, EventArgs e)
        {
            PopupSearchLookUpEditForm form = (sender as IPopupControl).PopupWindow as PopupSearchLookUpEditForm;
            SearchEditLookUpPopup popup = form.Controls.OfType<SearchEditLookUpPopup>().FirstOrDefault();
            LayoutControl layout = popup.Controls.OfType<LayoutControl>().FirstOrDefault();
            //如果窗体内空间没有确认按钮，则自定义确认simplebutton，取消simplebutton，选中结果label
            if (layout.Controls.OfType<Control>().Where(ct => ct.Name == "btOK").FirstOrDefault() == null)
            {
                //得到空的空间
                EmptySpaceItem a = layout.Items.Where(it => it.TypeName == "EmptySpaceItem").FirstOrDefault() as EmptySpaceItem;

                //得到取消按钮，重写点击事件
                Control clearBtn = layout.Controls.OfType<Control>().Where(ct => ct.Name == "btClear").FirstOrDefault();
                LayoutControlItem clearLCI = (LayoutControlItem)layout.GetItemByControl(clearBtn);
                clearBtn.Click += clear销售员Btn_Click;

                //添加一个simplebutton控件(确认按钮)
                LayoutControlItem myLCI = (LayoutControlItem)clearLCI.Owner.CreateLayoutItem(clearLCI.Parent);
                myLCI.TextVisible = false;
            }
        }
        private void searchLookUpEdit销售员View_Click(object sender, EventArgs e)
        {
            int[] a = this.searchLookUpEdit销售员.Properties.View.GetSelectedRows();
            if (a.Length > 0)
            {
                foreach (int rowHandle in a)
                {
                    String assistantId = this.searchLookUpEdit销售员.Properties.View.GetRowCellValue(rowHandle, "id").ToString();
                    String assistantName = this.searchLookUpEdit销售员.Properties.View.GetRowCellValue(rowHandle, "name").ToString();
                    String assistantMnemonic = this.searchLookUpEdit销售员.Properties.View.GetRowCellValue(rowHandle, "mnemonic").ToString();
                    this.verificationVO.buildAssistant(assistantId, assistantName, assistantMnemonic);
                }
            }
        }

        /// <summary>
        /// 清除按钮事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void clear销售员Btn_Click(object sender, EventArgs e)
        {
            this.searchLookUpEdit销售员.ToolTip = null;
            searchLookUpEdit销售员.EditValue = null;
        }
        private void searchLookUpEdit销售员_CustomDisplayText(object sender, DevExpress.XtraEditors.Controls.CustomDisplayTextEventArgs e)
        {
            if (null != e.Value)
                e.DisplayText = this.verificationVO.assistantName;
        }
        #endregion
        #region 成单人
        private void searchLookUpEdit成单人_Popup(object sender, EventArgs e)
        {
            PopupSearchLookUpEditForm form = (sender as IPopupControl).PopupWindow as PopupSearchLookUpEditForm;
            SearchEditLookUpPopup popup = form.Controls.OfType<SearchEditLookUpPopup>().FirstOrDefault();
            LayoutControl layout = popup.Controls.OfType<LayoutControl>().FirstOrDefault();
            //如果窗体内空间没有确认按钮，则自定义确认simplebutton，取消simplebutton，选中结果label
            if (layout.Controls.OfType<Control>().Where(ct => ct.Name == "btOK").FirstOrDefault() == null)
            {
                //得到空的空间
                EmptySpaceItem a = layout.Items.Where(it => it.TypeName == "EmptySpaceItem").FirstOrDefault() as EmptySpaceItem;

                //得到取消按钮，重写点击事件
                Control clearBtn = layout.Controls.OfType<Control>().Where(ct => ct.Name == "btClear").FirstOrDefault();
                LayoutControlItem clearLCI = (LayoutControlItem)layout.GetItemByControl(clearBtn);
                clearBtn.Click += clear成单人Btn_Click;

                //添加一个simplebutton控件(确认按钮)
                LayoutControlItem myLCI = (LayoutControlItem)clearLCI.Owner.CreateLayoutItem(clearLCI.Parent);
                myLCI.TextVisible = false;
            }
        }
        private void searchLookUpEdit成单人View_Click(object sender, EventArgs e)
        {
            int[] a = this.searchLookUpEdit成单人.Properties.View.GetSelectedRows();
            if (a.Length > 0)
            {
                foreach (int rowHandle in a)
                {
                    String salesId = this.searchLookUpEdit成单人.Properties.View.GetRowCellValue(rowHandle, "id").ToString();
                    String salesName = this.searchLookUpEdit成单人.Properties.View.GetRowCellValue(rowHandle, "name").ToString();
                    this.verificationVO.buildSales(salesId, salesName);
                }
            }
        }

        /// <summary>
        /// 清除按钮事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void clear成单人Btn_Click(object sender, EventArgs e)
        {
            this.searchLookUpEdit成单人.ToolTip = null;
            searchLookUpEdit成单人.EditValue = null;
        }
        private void searchLookUpEdit成单人_CustomDisplayText(object sender, DevExpress.XtraEditors.Controls.CustomDisplayTextEventArgs e)
        {
            if (null != e.Value)
                e.DisplayText = this.verificationVO.salesName;
        }
        #endregion
        #region 调价选店铺
        private void searchLookUpEdit店铺1_Popup(object sender, EventArgs e)
        {
            PopupSearchLookUpEditForm form = (sender as IPopupControl).PopupWindow as PopupSearchLookUpEditForm;
            SearchEditLookUpPopup popup = form.Controls.OfType<SearchEditLookUpPopup>().FirstOrDefault();
            LayoutControl layout = popup.Controls.OfType<LayoutControl>().FirstOrDefault();
            //如果窗体内空间没有确认按钮，则自定义确认simplebutton，取消simplebutton，选中结果label
            if (layout.Controls.OfType<Control>().Where(ct => ct.Name == "btOK").FirstOrDefault() == null)
            {
                //得到空的空间
                EmptySpaceItem a = layout.Items.Where(it => it.TypeName == "EmptySpaceItem").FirstOrDefault() as EmptySpaceItem;

                //得到取消按钮，重写点击事件
                Control clearBtn = layout.Controls.OfType<Control>().Where(ct => ct.Name == "btClear").FirstOrDefault();
                LayoutControlItem clearLCI = (LayoutControlItem)layout.GetItemByControl(clearBtn);
                clearBtn.Click += clear店铺1Btn_Click;

                //添加一个simplebutton控件(确认按钮)
                LayoutControlItem myLCI = (LayoutControlItem)clearLCI.Owner.CreateLayoutItem(clearLCI.Parent);
                myLCI.TextVisible = false;
            }
        }
        private void searchLookUpEdit店铺1View_Click(object sender, EventArgs e)
        {
            int[] a = this.searchLookUpEdit店铺1.Properties.View.GetSelectedRows();
            if (a.Length > 0)
            {
                foreach (int rowHandle in a)
                {
                    this.findStoreId = this.searchLookUpEdit店铺1.Properties.View.GetRowCellValue(rowHandle, "id").ToString();
                    this.findStoreName = this.searchLookUpEdit店铺1.Properties.View.GetRowCellValue(rowHandle, "name").ToString();
                    if (!System.IO.File.Exists(@"xml\config店铺.xml"))
                    {
                        DealXML.ObjectToXMLFile(new DTO销售表头(this.findStoreId, this.findStoreName), @"xml\config店铺.xml", Encoding.UTF8);
                    }
                }
            }
        }

        /// <summary>
        /// 清除按钮事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void clear店铺1Btn_Click(object sender, EventArgs e)
        {
            this.searchLookUpEdit店铺1.ToolTip = null;
            searchLookUpEdit店铺1.EditValue = null;
        }
        private void searchLookUpEdit店铺1_CustomDisplayText(object sender, DevExpress.XtraEditors.Controls.CustomDisplayTextEventArgs e)
        {
            if (null != e.Value)
                e.DisplayText = this.findStoreName;
        }
        #endregion
        #region 调价选销售员
        private void searchLookUpEdit销售员1_Popup(object sender, EventArgs e)
        {
            PopupSearchLookUpEditForm form = (sender as IPopupControl).PopupWindow as PopupSearchLookUpEditForm;
            SearchEditLookUpPopup popup = form.Controls.OfType<SearchEditLookUpPopup>().FirstOrDefault();
            LayoutControl layout = popup.Controls.OfType<LayoutControl>().FirstOrDefault();
            //如果窗体内空间没有确认按钮，则自定义确认simplebutton，取消simplebutton，选中结果label
            if (layout.Controls.OfType<Control>().Where(ct => ct.Name == "btOK").FirstOrDefault() == null)
            {
                //得到空的空间
                EmptySpaceItem a = layout.Items.Where(it => it.TypeName == "EmptySpaceItem").FirstOrDefault() as EmptySpaceItem;

                //得到取消按钮，重写点击事件
                Control clearBtn = layout.Controls.OfType<Control>().Where(ct => ct.Name == "btClear").FirstOrDefault();
                LayoutControlItem clearLCI = (LayoutControlItem)layout.GetItemByControl(clearBtn);
                clearBtn.Click += clear销售员1Btn_Click;

                //添加一个simplebutton控件(确认按钮)
                LayoutControlItem myLCI = (LayoutControlItem)clearLCI.Owner.CreateLayoutItem(clearLCI.Parent);
                myLCI.TextVisible = false;
            }
        }
        private void searchLookUpEdit销售员1View_Click(object sender, EventArgs e)
        {
            int[] a = this.searchLookUpEdit销售员1.Properties.View.GetSelectedRows();
            if (a.Length > 0)
            {
                foreach (int rowHandle in a)
                {
                    this.findAssistantId = this.searchLookUpEdit销售员1.Properties.View.GetRowCellValue(rowHandle, "id").ToString();
                    this.findAssistantName = this.searchLookUpEdit销售员1.Properties.View.GetRowCellValue(rowHandle, "name").ToString();
                }
            }
        }

        /// <summary>
        /// 清除按钮事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void clear销售员1Btn_Click(object sender, EventArgs e)
        {
            this.searchLookUpEdit销售员1.ToolTip = null;
            searchLookUpEdit销售员1.EditValue = null;
        }
        private void searchLookUpEdit销售员1_CustomDisplayText(object sender, DevExpress.XtraEditors.Controls.CustomDisplayTextEventArgs e)
        {
            if (null != e.Value)
                e.DisplayText = this.findAssistantName;
        }
        #endregion
        #region 选择面料
        /// <summary>
        /// 绑定清空事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void searchLookUpEdit面料_Popup(object sender, EventArgs e)
        {
            //得到当前SearchLookUpEdit弹出窗体
            PopupSearchLookUpEditForm form = (sender as IPopupControl).PopupWindow as PopupSearchLookUpEditForm;
            SearchEditLookUpPopup popup = form.Controls.OfType<SearchEditLookUpPopup>().FirstOrDefault();
            LayoutControl layout = popup.Controls.OfType<LayoutControl>().FirstOrDefault();
            //如果窗体内空间没有确认按钮，则自定义确认simplebutton，取消simplebutton，选中结果label
            if (layout.Controls.OfType<Control>().Where(ct => ct.Name == "btOK").FirstOrDefault() == null)
            {
                //得到空的空间
                EmptySpaceItem a = layout.Items.Where(it => it.TypeName == "EmptySpaceItem").FirstOrDefault() as EmptySpaceItem;

                //得到取消按钮，重写点击事件
                Control clearBtn = layout.Controls.OfType<Control>().Where(ct => ct.Name == "btClear").FirstOrDefault();
                LayoutControlItem clearLCI = (LayoutControlItem)layout.GetItemByControl(clearBtn);
                clearBtn.Click += clearBtn_Click;

                //添加一个simplebutton控件(确认按钮)
                LayoutControlItem myLCI = (LayoutControlItem)clearLCI.Owner.CreateLayoutItem(clearLCI.Parent);
                myLCI.TextVisible = false;
            }
        }
        /// <summary>
        /// 点击选择后的行为
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void searchLookUpEdit面料View_Click(object sender, EventArgs e)
        {
            var a = this.searchLookUpEdit面料.Properties.View.GetSelectedRows();
            foreach (int rowHandle in a)
            {
                this.materialCode = this.searchLookUpEdit面料.Properties.View.GetRowCellValue(rowHandle, "materialCode").ToString();
                this.materialNameCn = this.searchLookUpEdit面料.Properties.View.GetRowCellValue(rowHandle, "materialNameCn").ToString();
            }

            //传materialCode到customerMadeSaleConfirmDTO
            if (null == this.customerMadeSaleConfirmDTO)
            {
                MessageBox.Show("请重新扫码");
                return;
            }
            this.textBox定制面料号.Text = this.materialCode;
            this.textBox定制面料名称.Text = this.materialNameCn;
            this.customerMadeSaleConfirmDTO.buildMaterialCode(materialCode);
        }

        /// <summary>
        /// 清除按钮事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void clearBtn_Click(object sender, EventArgs e)
        {
            this.searchLookUpEdit面料.ToolTip = null;
            searchLookUpEdit面料.EditValue = null;
        }
        /// <summary>
        /// 选完之后的显示
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void searchLookUpEdit面料_CustomDisplayText(object sender, DevExpress.XtraEditors.Controls.CustomDisplayTextEventArgs e)
        {
            if (null != e.Value)
                e.DisplayText = this.materialCode;
        }
        #endregion
        #region 定制选参考成衣
        /// <summary>
        /// 绑定清空事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void searchLookUpEdit定制选择参考成衣_Popup(object sender, EventArgs e)
        {
            //得到当前SearchLookUpEdit弹出窗体
            PopupSearchLookUpEditForm form = (sender as IPopupControl).PopupWindow as PopupSearchLookUpEditForm;
            SearchEditLookUpPopup popup = form.Controls.OfType<SearchEditLookUpPopup>().FirstOrDefault();
            LayoutControl layout = popup.Controls.OfType<LayoutControl>().FirstOrDefault();
            //如果窗体内空间没有确认按钮，则自定义确认simplebutton，取消simplebutton，选中结果label
            if (layout.Controls.OfType<Control>().Where(ct => ct.Name == "btOK").FirstOrDefault() == null)
            {
                //得到空的空间
                EmptySpaceItem a = layout.Items.Where(it => it.TypeName == "EmptySpaceItem").FirstOrDefault() as EmptySpaceItem;

                //得到取消按钮，重写点击事件
                Control clearBtn = layout.Controls.OfType<Control>().Where(ct => ct.Name == "btClear").FirstOrDefault();
                LayoutControlItem clearLCI = (LayoutControlItem)layout.GetItemByControl(clearBtn);
                clearBtn.Click += clearBtn定制选择参考成衣_Click;

                //添加一个simplebutton控件(确认按钮)
                LayoutControlItem myLCI = (LayoutControlItem)clearLCI.Owner.CreateLayoutItem(clearLCI.Parent);
                myLCI.TextVisible = false;
            }
        }
        /// <summary>
        /// 点击选择后的行为
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void searchLookUpEdit定制选择参考成衣View_Click(object sender, EventArgs e)
        {
            var a = this.searchLookUpEdit定制选择参考成衣.Properties.View.GetSelectedRows();
            foreach (int rowHandle in a)
            {
                this.barCode = this.searchLookUpEdit定制选择参考成衣.Properties.View.GetRowCellValue(rowHandle, "stockInventoryNo").ToString();
            }
            this.textBox定制扫码.Text = this.barCode;
            this.customerMadeSaleConfirmDTO = new CustomerMadeSaleConfirmDTO(this.barCode);
            OrderCommitDTO返回 orderCommitDTO返回 = MTO订单Service.getOrderCommitDtoByBarcode(barCode);
            this.comboBox定制尺码.Items.Clear();
            List<String> 尺码 = new List<string>();
            尺码 = MTO订单Service.findSizeCdByStyleNameCn(orderCommitDTO返回.styleNameCn);
            foreach (String str in 尺码)
            {
                this.comboBox定制尺码.Items.Add(str);
            }
            this.display定制Text(orderCommitDTO返回);

        }
        /// <summary>
        /// 清除按钮事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void clearBtn定制选择参考成衣_Click(object sender, EventArgs e)
        {
            this.searchLookUpEdit定制选择参考成衣.ToolTip = null;
            searchLookUpEdit定制选择参考成衣.EditValue = null;
        }
        /// <summary>
        /// 选完之后的显示
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void searchLookUpEdit定制选择参考成衣_CustomDisplayText(object sender, DevExpress.XtraEditors.Controls.CustomDisplayTextEventArgs e)
        {
            if (null != e.Value)
                e.DisplayText = this.barCode;
        }
        #endregion
        #region 选择客套参考成衣
        /// <summary>
        /// 绑定清空事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void searchLookUpEdit选择客套参考成衣_Popup(object sender, EventArgs e)
        {
            //得到当前SearchLookUpEdit弹出窗体
            PopupSearchLookUpEditForm form = (sender as IPopupControl).PopupWindow as PopupSearchLookUpEditForm;
            SearchEditLookUpPopup popup = form.Controls.OfType<SearchEditLookUpPopup>().FirstOrDefault();
            LayoutControl layout = popup.Controls.OfType<LayoutControl>().FirstOrDefault();
            //如果窗体内空间没有确认按钮，则自定义确认simplebutton，取消simplebutton，选中结果label
            if (layout.Controls.OfType<Control>().Where(ct => ct.Name == "btOK").FirstOrDefault() == null)
            {
                //得到空的空间
                EmptySpaceItem a = layout.Items.Where(it => it.TypeName == "EmptySpaceItem").FirstOrDefault() as EmptySpaceItem;

                //得到取消按钮，重写点击事件
                Control clearBtn = layout.Controls.OfType<Control>().Where(ct => ct.Name == "btClear").FirstOrDefault();
                LayoutControlItem clearLCI = (LayoutControlItem)layout.GetItemByControl(clearBtn);
                clearBtn.Click += clearBtn选择客套参考成衣_Click;

                //添加一个simplebutton控件(确认按钮)
                LayoutControlItem myLCI = (LayoutControlItem)clearLCI.Owner.CreateLayoutItem(clearLCI.Parent);
                myLCI.TextVisible = false;
            }
        }
        /// <summary>
        /// 点击选择后的行为
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void searchLookUpEdit选择客套参考成衣View_Click(object sender, EventArgs e)
        {
            var a = this.searchLookUpEdit选择客套参考成衣.Properties.View.GetSelectedRows();
            foreach (int rowHandle in a)
            {
                this.barCode = this.searchLookUpEdit选择客套参考成衣.Properties.View.GetRowCellValue(rowHandle, "stockInventoryNo").ToString();
            }
            this.textBox客套成衣扫码.Text = this.barCode;
            OrderCommitDTO返回 orderCommitDTO返回 = MTO订单Service.getOrderCommitDtoByBarcode(barCode);
            this.comboBox客套尺码.Items.Clear();
            List<String> 尺码 = new List<string>();
            尺码 = MTO订单Service.findSizeCdByStyleNameCn(orderCommitDTO返回.styleNameCn);
            foreach (String str in 尺码)
            {
                this.comboBox客套尺码.Items.Add(str);
            }
            this.display客套Text(orderCommitDTO返回);

        }
        /// <summary>
        /// 清除按钮事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void clearBtn选择客套参考成衣_Click(object sender, EventArgs e)
        {
            this.searchLookUpEdit选择客套参考成衣.ToolTip = null;
            searchLookUpEdit选择客套参考成衣.EditValue = null;
        }
        /// <summary>
        /// 选完之后的显示
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void searchLookUpEdit选择客套参考成衣_CustomDisplayText(object sender, DevExpress.XtraEditors.Controls.CustomDisplayTextEventArgs e)
        {
            if (null != e.Value)
                e.DisplayText = this.barCode;
        }
        #endregion
        #endregion

        #region 02 gridControl颜色标注及尺寸清洗
        //gridControl尺寸清洗
        private void bandedGridViewTitle_CustomColumnDisplayText(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDisplayTextEventArgs e)
        {
            if (e.Column.Name.Equals("gridColumn尺码"))
            {
                if (!String.IsNullOrWhiteSpace(e.DisplayText))
                {
                    try { e.DisplayText = e.DisplayText.Replace("IGS_GROUP_SIZE-", "").Replace("EGS_GROUP_SIZE-", ""); } catch { }
                }
            }
            if (e.Column.Name.Equals("gridColumn业务类型"))
            {
                if ("套号销售出库".Equals(e.DisplayText))
                {
                    try { e.DisplayText = "在库产品"; } catch { }
                }
                else if ("客户套号".Equals(e.DisplayText))
                {
                    try { e.DisplayText = "客套下单"; } catch { }
                }
            }
        }
        private void bandedGridViewTitle_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e)
        {
            if (e.Column.Name.Equals("gridColumn是否同步销售订单"))
            {
                if (Convert.ToBoolean(e.CellValue.ToString()))
                {
                    //e.Appearance.BackColor = Color.Green;
                }
                else
                {
                    e.Appearance.BackColor = Color.Red;
                }
            }
        }
        private void gridViewDetail_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e)
        {
            if (e.Column.Name.Equals("gridColumn业务类型detail"))
            {
                if ("套号下单".Equals(e.CellValue.ToString()))
                {
                    e.Appearance.BackColor = Color.LightYellow;
                }
                else if ("定制下单".Equals(e.CellValue.ToString()))
                {
                    e.Appearance.BackColor = Color.LightGreen;
                }
                else if ("客户套号".Equals(e.CellValue.ToString()))
                {
                    e.Appearance.BackColor = Color.LightPink;
                }
                else if ("商品调价".Equals(e.CellValue.ToString()))
                {
                    e.Appearance.BackColor = Color.LightCoral;
                }
                else if ("设计费用".Equals(e.CellValue.ToString()))
                {
                    e.Appearance.BackColor = Color.LightBlue;
                }
            }
        }
        #endregion

        #region 03 单个订单商品调价事件
        private void 商品调价ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            String quoteId = FunctionHelper.GetbandedgridViewValue(this.bandedGridViewTitle, this.bandedGridViewTitle.FocusedRowHandle, "id");
            new Form商品调价(quoteId).ShowDialog();
            this.刷新客户当天销售日记账();
        }
        private void 设计费用ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            String businessType = FunctionHelper.GetbandedgridViewValue(this.bandedGridViewTitle, this.bandedGridViewTitle.FocusedRowHandle, "businessType");
            String quoteId = FunctionHelper.GetbandedgridViewValue(this.bandedGridViewTitle, this.bandedGridViewTitle.FocusedRowHandle, "id");
            if ("定制下单".Equals(businessType))
            {
                new Form设计费(quoteId).ShowDialog();
                this.刷新客户当天销售日记账();
            }
            else
            {
                MessageBox.Show("非定制订单不能修改设计费");
                return;
            }
        }
        #endregion

        private void simpleButton添加客户0_Click(object sender, EventArgs e)
        {
            new FormMTO添加客户地址(this.customerPDTO).ShowDialog();
            this.手机号查找信息并赋值(this.customerPDTO.mobile);
            this.textBox手机号查找0.Clear();
        }
        private void textBox手机号查找0_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyValue == 13)
            {
                this.customerPDTO = MTO订单Service.getCustomerPByMobile(this.textBox手机号查找0.Text.Trim());
                if (String.IsNullOrEmpty(this.customerPDTO.mobile))
                {
                    MessageBox.Show("未创建用户");
                    return;
                }
                this.手机号查找信息并赋值(this.customerPDTO.mobile);
                this.textBox手机号查找0.Clear();
                this.调价记录();
            }
        }
        private void simpleButton更多客户_Click(object sender, EventArgs e)
        {
            new FormMTO客户一览(this.customerPDTO).ShowDialog();
            this.手机号查找信息并赋值(this.customerPDTO.mobile);
            this.textBox手机号查找0.Clear();
        }
        private void 调价记录()
        {
            this.dateTimeStr = this.dateTimePicker交期.Value.ToString("yyyy-MM-dd");
            this.customerDailyDiscountDTO = 销售确认Service.getCustomerDailyDiscountByDateStampAndMobile(dateTimeStr, mobile);
            this.textBox客户电话.Text = String.IsNullOrEmpty(this.customerDailyDiscountDTO.mobile) ? this.mobile : this.customerDailyDiscountDTO.mobile;
            this.textBox时间戳.Text = String.IsNullOrEmpty(this.customerDailyDiscountDTO.dateStamp) ? this.dateTimeStr : this.customerDailyDiscountDTO.dateStamp;
            this.textBox调价销售组织.Text = this.customerDailyDiscountDTO.storeName;
            this.textBox调价负责人.Text = this.customerDailyDiscountDTO.assistantName;
            this.textBox调价原因.Text = this.customerDailyDiscountDTO.priceAdjustReason;
            this.textBox调整价格.Text = this.customerDailyDiscountDTO.adjustPrice.ToString();

            this.findStoreId = this.customerDailyDiscountDTO.store;
            this.findStoreName = this.customerDailyDiscountDTO.storeName;
            this.findAssistantId = this.customerDailyDiscountDTO.assistant;
            this.findAssistantName = this.customerDailyDiscountDTO.assistantName;
        }
        private void simpleButton确认客户整体调价_Click(object sender, EventArgs e)
        {
            this.customerDailyDiscountDTO =
                new CustomerDailyDiscountDTO(
                    this.textBox客户电话.Text.Trim(),
                    this.textBox时间戳.Text.Trim(),
                    this.findStoreId,
                    this.findAssistantId,
                    this.textBox调价原因.Text.Trim(),
                    Convert.ToDouble(this.textBox调整价格.Text.Trim())
                    );
            DTO返回值判断 dTO = 销售确认Service.saveCustomerDailyDiscount(this.customerDailyDiscountDTO);
            //调用调价确认
            销售确认Service.saveCustomerDailyDefect(mobile, "调价确认");
            if (!"200".Equals(dTO.errorCode))
            {
                MessageBox.Show(dTO.errorMessage);
            }
            else
            {
                MessageBox.Show("操作成功");
            }
            this.调价记录();
        }
        private void simpleButton特价款下单1_Click(object sender, EventArgs e)
        {
            this.textBox销售出库扫描.Text = "20210329-87y";
            this.ActiveControl = this.textBox销售出库扫描;
        }
        private void textBox销售出库扫描_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyValue == 13)
            {
                if (!this.verificationVO.build判空())
                {
                    MessageBox.Show("请选择店铺、销售员");
                    return;
                }
                if (!String.IsNullOrWhiteSpace(this.textBox销售出库扫描.Text.Trim()))
                {
                    try
                    {
                        this.saleStockInOutDetailDTO =
                            成品出库单Service.preStockInOutDetailWithCustomerInfoByBarcode(
                            this.saleSessionId,
                            this.textBox销售出库扫描.Text.Trim(),
                            0,
                            StockInOutTypeConst.ShopSaleOut,
                            this.verificationVO.storeId
                            );
                        try { this.saleStockInOutDetailDTO.styleSizeCd = this.saleStockInOutDetailDTO.styleSizeCd.Replace("IGS_GROUP_SIZE-", "").Replace("EGS_GROUP_SIZE-", ""); } catch { }
                        if (!String.IsNullOrEmpty(this.saleStockInOutDetailDTO.barcode))
                        {
                            if (this.saleStockInOutDetailDTOs.Count > 0)
                            {
                                if (!this.saleStockInOutDetailDTOs.Exists(dto => dto.barcode.Equals(this.saleStockInOutDetailDTO.barcode)))
                                {
                                    this.saleStockInOutDetailDTOs.Add(this.saleStockInOutDetailDTO);
                                }
                            }
                            else
                            {
                                this.saleStockInOutDetailDTOs.Add(this.saleStockInOutDetailDTO);
                            }
                        }
                        this.gridControl门店销售出库.DataSource = this.saleStockInOutDetailDTOs;
                        this.gridView门店销售出库.RefreshData();
                        this.gridView门店销售出库.BestFitColumns();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                    this.textBox销售出库扫描.Clear();
                }
            }
        }
        private void simpleButton销售出库确认_Click(object sender, EventArgs e)
        {
            if (this.saleStockInOutDetailDTOs.Count > 0)
            {
                if (String.IsNullOrWhiteSpace(this.textBox联系电话.Text.Trim()))
                {
                    MessageBox.Show("请将客户信息补充完整");
                    return;
                }
                try
                {
                    //  现货销售出库
                    //this.saleStockInOutTitleDTO =
                    //    出入库Service.saveStockSaleOut(
                    //        this.saleSessionId,
                    //        this.verificationVO.storeId,
                    //        this.verificationVO.storeName,
                    //        this.verificationVO.assistantMnemonic,
                    //        this.textBox客户姓名.Text.Trim(),
                    //        "",
                    //        this.textBox联系电话.Text.Trim(),
                    //        this.textBox详细地址.Text.Trim()
                    //        );
                    try
                    {
                        //销售出库
                        //List<GarmentSaleConfirmDTO> garmentSaleConfirmDTOs = new List<GarmentSaleConfirmDTO>();
                        List<GarmentSaleConfirmDTO> garmentSaleConfirmRequestDTOs = new List<GarmentSaleConfirmDTO>();
                        foreach (StockInOutDetailDTO item in this.saleStockInOutDetailDTOs)
                        {
                            //garmentSaleConfirmDTOs.Add(
                            //    new GarmentSaleConfirmDTO(this.textBox联系电话.Text.Trim(), item.barcode, this.verificationVO.storeId, this.verificationVO.assistantMnemonic, false));
                            //  是否为特价款
                            if ("20210329-87y".Equals(item.barcode))
                            {
                                garmentSaleConfirmRequestDTOs.Add(
                                new GarmentSaleConfirmDTO(this.textBox联系电话.Text.Trim(), item.barcode, this.verificationVO.storeId, this.verificationVO.assistantId, true));
                            }
                            else
                            {
                                garmentSaleConfirmRequestDTOs.Add(
                                new GarmentSaleConfirmDTO(this.textBox联系电话.Text.Trim(), item.barcode, this.verificationVO.storeId, this.verificationVO.assistantId, false));
                            }
                        }
                        //  出库并提交销售确认
                        StockInOutTitleDTO saleStockInOutTitleDTO =
                            出入库Service.storeSaveStockSaleOutWith(
                                this.verificationVO.storeId,
                                this.verificationVO.storeName,
                                this.verificationVO.assistantMnemonic,
                                this.textBox客户姓名.Text.Trim(),
                                "",
                                this.textBox联系电话.Text.Trim(),
                                this.textBox详细地址.Text.Trim(),
                                String.IsNullOrEmpty(this.verificationVO.salesId) ? this.verificationVO.assistantId : this.verificationVO.salesId,
                                this.checkBox是否会员账户扣款.Checked ? "账户余额支付" : "现金支付",
                                garmentSaleConfirmRequestDTOs
                            );
                        FunctionHelper.JsonSerialization(saleStockInOutTitleDTO);
                        if (String.IsNullOrEmpty(saleStockInOutTitleDTO.id))
                        {
                            MessageBox.Show("销售出库失败");
                        }
                        else
                        {
                            MessageBox.Show("销售出库成功");
                        }

                        //  提交销售确认
                        //List<GarmentSaleConfirmDTO> 返回值garmentSaleConfirmDTOs = 销售确认Service.saveGarmentSaleConfirm(garmentSaleConfirmRequestDTOs);

                    }
                    catch { }
                    //
                    this.saleSessionId = new FunctionHelper().Uuid;
                    this.saleStockInOutDetailDTOs.Clear();
                    this.saleStockInOutDetailDTO = new StockInOutDetailDTO();
                    this.gridControl门店销售出库.DataSource = this.saleStockInOutDetailDTOs;
                    this.gridView门店销售出库.RefreshData();
                    this.gridView门店销售出库.BestFitColumns();
                    this.刷新客户当天销售日记账();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
            else
            {
                MessageBox.Show("无确认数据");
            }
        }
        /// <summary>
        /// 扫码显示款式信息
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void textBox定制扫码_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyValue == 13)
            {
                if (!String.IsNullOrWhiteSpace(textBox定制扫码.Text))
                {
                    this.customerMadeSaleConfirmDTO = new CustomerMadeSaleConfirmDTO(textBox定制扫码.Text.Trim());
                    OrderCommitDTO返回 orderCommitDTO返回 = MTO订单Service.getOrderCommitDtoByBarcode(textBox定制扫码.Text.Trim());
                    this.display定制Text(orderCommitDTO返回);
                    this.textBox定制扫码.Clear();
                    //显示该款式的尺码组
                    this.comboBox定制尺码.Items.Clear();
                    List<String> 尺码 = new List<string>();
                    尺码 = MTO订单Service.findSizeCdByStyleNameCn(orderCommitDTO返回.styleNameCn);
                    foreach (String str in 尺码)
                    {
                        this.comboBox定制尺码.Items.Add(str);
                    }
                }
            }
        }
        /// <summary>
        /// 显示款式信息
        /// </summary>
        /// <param name="orderCommitDTO返回"></param>
        private void display定制Text(OrderCommitDTO返回 orderCommitDTO返回)
        {
            //扫码从orderCommitDTO传进来款式 面料 价格
            this.barCode = this.textBox定制扫码.Text.Trim();
            this.textBox定制款式名称.Text = orderCommitDTO返回.styleNameCn;
            this.textBox定制面料号.Text = orderCommitDTO返回.materialCode;
            this.textBox定制面料名称.Text = orderCommitDTO返回.materialNameCn;
            //加载款式图片
            this.model = new 订单预览新Model(this.textBox定制扫码.Text.Trim(), Enum订单查询.按照水洗标查询订单);
            this.定制订单信息呈现();
        }
        private void simpleButton定制提交_Click(object sender, EventArgs e)
        {
            //try
            //{
            //    this.saleModel = new 下单Model(this, "定制下单");
            //    this.saleModel.verify定制下单();
            //}
            //catch (Exception excepption)
            //{
            //    MessageBox.Show(excepption.Message);
            //}
            if (String.IsNullOrEmpty(this.mobile))
            {
                MessageBox.Show("请将客户信息补充完整");
                return;
            }
            if (!this.verificationVO.build判空())
            {
                MessageBox.Show("请选择店铺、销售员");
                return;
            }
            if ((!String.IsNullOrWhiteSpace(this.textBox定制款式名称.Text))
                && (!String.IsNullOrWhiteSpace(this.comboBox定制尺码.Text))
                && (!String.IsNullOrWhiteSpace(this.numericUpDown定制数量.Value.ToString())))
            {
                //build前customerMadeSaleConfirmDTO判空
                if (null == this.customerMadeSaleConfirmDTO)
                {
                    MessageBox.Show("请重新扫码");
                    return;
                }
                else
                {
                    this.customerMadeSaleConfirmDTO.build("IGS_GROUP_SIZE-" + this.comboBox定制尺码.Text.Trim(),
                                            Convert.ToInt32(this.numericUpDown定制数量.Value.ToString()),
                                            this.richTextBox定制备注.Text.Trim());
                }
                if (!String.IsNullOrWhiteSpace(this.materialCode))
                {
                    this.customerMadeSaleConfirmDTOs.Add(this.customerMadeSaleConfirmDTO);
                }
                else
                {
                    this.customerMadeSaleConfirmDTOs.Add(
                    new CustomerMadeSaleConfirmDTO(
                        this.barCode,
                        "IGS_GROUP_SIZE-" + this.comboBox定制尺码.Text.Trim(),
                        Convert.ToInt32(this.numericUpDown定制数量.Value.ToString()),
                        this.richTextBox定制备注.Text.Trim()
                        )
                );
                }
                //this.refresh定制Details();
                this.textBox定制扫码.Clear();
                this.ActiveControl = this.textBox定制扫码;
                this.comboBox定制尺码.Items.Clear();
            }
            else
            {
                MessageBox.Show("请补充款式信息");
                return;
            }
            if (this.customerMadeSaleConfirmDTOs.Count > 0)
            {
                List<String> re =
                    销售确认Service.saveCustomerMadeSaleCacheWith(
                    this.mobile,
                    this.verificationVO.storeId,
                    this.verificationVO.assistantId,
                    String.IsNullOrEmpty(this.verificationVO.salesId) ? this.verificationVO.assistantId : this.verificationVO.salesId,
                    this.checkBox是否会员账户扣款.Checked ? "账户余额支付" : "现金支付",
                    this.customerMadeSaleConfirmDTOs
                    );
                //清空customerMadeSaleConfirmDTO
                this.customerMadeSaleConfirmDTO = null;
                //定制下单成功，如果详细地址为空调用
                foreach (String id in re)
                {
                    销售确认Service.调用QC(this.mobile, this.textBox详细地址.Text.Trim(), true, id);
                    //判断是否补充客户标签
                    Boolean is补充客户标签 = 销售确认Service.judgePresentByMobile(mobile);
                    if (!is补充客户标签)
                    {
                        销售确认Service.saveCustomerDailyDefect(mobile, "补充客户标签");
                    }
                }

                //MessageBox.Show("提交成功");
                this.clear定制All();
                this.刷新客户当天销售日记账();
            }
        }

        #region 客套下单事件
        private void textBox客套成衣扫码_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyValue == 13)
            {
                if (!this.verificationVO.build判空())
                {
                    MessageBox.Show("请选择店铺、销售员");
                    return;
                }
                if (!String.IsNullOrWhiteSpace(textBox客套成衣扫码.Text))
                {
                    OrderCommitDTO返回 orderCommitDTO返回 = MTO订单Service.getOrderCommitDtoByBarcode(textBox客套成衣扫码.Text.Trim());
                    this.display客套Text(orderCommitDTO返回);
                    this.textBox客套成衣扫码.Clear();

                    //显示该款式的尺码组
                    this.comboBox客套尺码.Items.Clear();
                    List<String> 尺码 = new List<string>();
                    尺码 = MTO订单Service.findSizeCdByStyleNameCn(orderCommitDTO返回.styleNameCn);
                    foreach (String str in 尺码)
                    {
                        this.comboBox客套尺码.Items.Add(str);
                    }
                }
                else
                {
                    MessageBox.Show("成衣码为空");
                    return;
                }
            }
        }
        //扫码后款式信息显示
        private void display客套Text(OrderCommitDTO返回 orderCommitDTO返回)
        {
            this.orderCommitDTO返回 = orderCommitDTO返回;
            //扫码从orderCommitDTO传进来款式 面料 价格
            this.barCode = this.textBox客套成衣扫码.Text.Trim();
            this.textBox客套款式名称.Text = orderCommitDTO返回.styleNameCn;
            this.textBox客套面料号.Text = orderCommitDTO返回.materialCode;
            this.textBox客套面料名称.Text = orderCommitDTO返回.materialNameCn;
            this.textBox客套建议零售价.Text = orderCommitDTO返回.price.ToString();
            //加载款式图片
            this.model = new 订单预览新Model(this.textBox客套成衣扫码.Text.Trim(), Enum订单查询.按照水洗标查询订单);
            this.套号订单信息呈现();
        }

        private void simpleButton客套提交_Click(object sender, EventArgs e)
        {
            if (String.IsNullOrEmpty(this.mobile))
            {
                MessageBox.Show("请将客户信息补充完整");
                return;
            }
            if (!this.verificationVO.build判空())
            {
                MessageBox.Show("请选择店铺、销售员");
                return;
            }
            if ((String.IsNullOrWhiteSpace(textBox客套款式名称.Text))
            || (String.IsNullOrWhiteSpace(comboBox客套尺码.Text))
            || (String.IsNullOrWhiteSpace(numericUpDown客套订单数量.Text)))
            {
                MessageBox.Show("请补充款式信息");
                return;
            }

            List<SaleOrderDetailRequestDTO> saleOrderDetailRequestDTOList = new List<SaleOrderDetailRequestDTO>();
            //saleOrderDetailDTOs是一个list，每次add添加SaleOrderDetailDTO对象
            //SaleOrderDetailDTO由传进来的OrderCommitDTO返回和其他参数组成
            saleOrderDetailRequestDTOList.Add(
                new SaleOrderDetailRequestDTO(
                this.barCode,
                Convert.ToInt32(this.numericUpDown客套订单数量.Value.ToString()),
                this.richTextBox定制备注.Text.Trim(),
                "IGS_GROUP_SIZE-" + this.comboBox客套尺码.Text.Trim(),
                new 下单MTO.Service.CustomerOrderCommitDTO(customerPDTO),
                this.textBox客套款式名称.Text.Trim(),
                this.textBox客套面料号.Text.Trim())
                );
            //this.refresh客套Details();

            //清空客户信息
            this.clearItem();

            //调用Service创建方法，传SaleOrderFacadeDTO
            //SaleOrderFacadeDTO由抬头和detail组成
            //MTO订单Service.createSaleOrder(
            SaleOrderRequestFacadeDTO saleOrderRequestFacadeDTO =
                new SaleOrderRequestFacadeDTO(
                    new SaleOrderTitleRequstDTO(
                        "客户套号",
                        this.verificationVO.storeId,
                        this.verificationVO.assistantId,
                        this.dateTimePicker交期.Value
                        ),
                    saleOrderDetailRequestDTOList
                );
            MTO订单Service.createSaleOrderAndSaveRecordWith(
                this.verificationVO.assistantMnemonic,
                String.IsNullOrEmpty(this.verificationVO.salesId) ? this.verificationVO.assistantId : this.verificationVO.salesId,
                this.checkBox是否会员账户扣款.Checked ? "账户余额支付" : "现金支付",
                saleOrderRequestFacadeDTO
                );
            //调用补充客户地址
            销售确认Service.saveCustomerDailyDefect(mobile, "补充客户地址");
            //判断是否补充客户标签
            Boolean is补充客户标签 = 销售确认Service.judgePresentByMobile(mobile);
            if (!is补充客户标签)
            {
                销售确认Service.saveCustomerDailyDefect(mobile, "补充客户标签");
            }
            //MessageBox.Show("下单成功");
            //new FormMTO下单提交预览(saleOrderRequestFacadeDTO).ShowDialog();
            this.刷新客户当天销售日记账();
        }

        #endregion
        #endregion

        #region 选择客户后刷新历史订单 添加商品后刷新日记账

        private void 手机号查找信息并赋值(String getMobile)
        {
            //根据电话号实例化对象并给textbox赋值
            this.mobile = getMobile;
            //this.customerPDTO = CRM客户Service.getCustomerPByMobile(getMobile);
            if (String.IsNullOrEmpty(getMobile))
            {
                MessageBox.Show("客户电话为空");
                return;
            }
            CustomerPWithIdentityAndScoreDTO customerPWithIdentityDTO = CRM客户Service.getCustomerPWithIdentityAndScoreByMobile(getMobile);
            this.customerPDTO = customerPWithIdentityDTO.customerPDTO;
            this.textBox客户姓名.Text = this.customerPDTO.customerName;
            this.textBox联系电话.Text = this.customerPDTO.mobile;
            this.textBox详细地址.Text =
                this.customerPDTO.addressProvince
                + this.customerPDTO.addressCity
                + this.customerPDTO.addressDistrict
                + this.customerPDTO.addressDetail;
            //  客户认证信息
            this.textBox会员号.Text = customerPWithIdentityDTO.customerIdentityDTO.memberId;
            this.textBox客户来源.Text = customerPWithIdentityDTO.customerIdentityDTO.saleSource;
            this.textBox客户负责人.Text = customerPWithIdentityDTO.customerIdentityDTO.responser;
            //  会员积分
            this.textEdit会员积分.Text = customerPWithIdentityDTO.confirmdScore.ToString();
            //刷新客户当天销售日记账
            this.gridControl订单.DataSource = 销售确认Service.getDaySaleConfirmListWithBalanceByMobile(this.mobile).saleConfirmQueryTitileDTOS;
            this.bandedGridViewTitle.RefreshData();
            //查询历史订单
            this.gridControl历史订单.DataSource = 订单预览新Service.getHistoryOrderCommitByMobile(mobile);
            this.gridView历史订单.RefreshData();
            //  判断是否可以从会员账户扣款
            //Double accountBalance = 销售确认Service.getAccountBalance(getMobile);
            AccountBalanceAndMerbershipDTO accountBalanceAndMerbership = 销售确认Service.getAccountBalanceAndMerbershipByMobile(getMobile);
            this.textEdit会员类型.Text = accountBalanceAndMerbership.membershipType;
            this.textEdit会员类型.ForeColor = Color.Red;
            this.textEdit账户余额.Text = Math.Round(accountBalanceAndMerbership.accountBalance).ToString();
            this.textBox充值账户余额.Text = Math.Round(accountBalanceAndMerbership.commonAccountBalance).ToString();
            if ("充值会员".Equals(accountBalanceAndMerbership.membershipType))
            {
                this.checkBox是否会员账户扣款.Checked = true;
                this.checkBox是否会员账户扣款.Enabled = false;
            }
            else
            {
                this.checkBox是否会员账户扣款.Checked = false;
                this.checkBox是否会员账户扣款.Enabled = false;
            }
            //this.customerSaleOrderReportDTO = 销售确认Service.getViewSaleInfoDaoByMobile(getMobile);
        }
        public void 刷新客户当天销售日记账()
        {
            SaleConfirmQueryTitileWithBalanceDTO saleConfirmQueryTitileWithBalanceDTO = 销售确认Service.getDaySaleConfirmListWithBalanceByMobile(this.mobile);
            //销售日记账刷新绑定数据源
            this.gridControl订单.DataSource = saleConfirmQueryTitileWithBalanceDTO.saleConfirmQueryTitileDTOS;
            this.bandedGridViewTitle.RefreshData();
            //当是账户余额支付
            if (this.checkBox是否会员账户扣款.Checked)
            {
                //当接口返回冲正金额大于0
                if(saleConfirmQueryTitileWithBalanceDTO.balance > 0)
                {
                    //弹框提示是否需要额外支付
                    MessageBox.Show("客户需额外支付 "+ saleConfirmQueryTitileWithBalanceDTO.balance +" 元");
                }
            }
        }
        #endregion

        #region 添加商品后控件清空行为
        //定制提交后清空
        private void clear定制All()
        {
            this.customerMadeSaleConfirmDTOs.Clear();
            this.textBox定制扫码.Clear();
            this.textBox定制款式名称.Clear();
            this.textBox定制面料号.Clear();
            this.textBox定制面料名称.Clear();
            this.comboBox定制尺码.Items.Clear();
            this.richTextBox定制备注.Clear();
            this.barCode = null;
            this.searchLookUpEdit定制选择参考成衣.Text = null;
        }
        //客套提交后清空
        private void clearItem()
        {
            this.textBox客套款式名称.Clear();
            this.textBox客套面料号.Clear();
            this.textBox客套面料名称.Clear();
            this.textBox客套建议零售价.Clear();
        }
        #endregion

        #region 加载图片
        private void 定制订单信息呈现()
        {
            //显示成衣码查询出内容，无参考意义的进行清空
            this.model.buildCustomerClear().build销售渠道Clear().buildOrderCommit().buildStyleCategoryDTOAndClear().buildClear刺绣();
            //门店定制下单销售渠道赋值
            this.model.build销售渠道("门店下单", "春衫定制");

            //款式
            this.gridControl定制款式.DataSource = this.model.款式DTOs;
            //设计点
            try
            {
                if (this.model.设计点DTOs.Count == 0)
                {
                    this.model.设计点DTOs = 下单相关Service.select接口查设计点(this.model.OrderCommitDTO返回.styleNameCn);
                }
            }
            catch { }
        }
        private void 套号订单信息呈现()
        {
            //显示成衣码查询出内容，无参考意义的进行清空
            this.model.buildCustomerClear().build销售渠道Clear().buildOrderCommit().buildStyleCategoryDTOAndClear().buildClear刺绣();
            //门店定制下单销售渠道赋值
            this.model.build销售渠道("门店下单", "春衫定制");

            //款式
            this.gridControl套号款式.DataSource = this.model.款式DTOs;
            //设计点
            try
            {
                if (this.model.设计点DTOs.Count == 0)
                {
                    this.model.设计点DTOs = 下单相关Service.select接口查设计点(this.model.OrderCommitDTO返回.styleNameCn);
                }
            }
            catch { }
        }
        #endregion

        private void comboBox折扣_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (this.comboBox折扣.SelectedIndex == 0)
            {
                this.changePrice = 0 - this.finalPrice * 0.05;
                this.textBox调整价格.Text = this.changePrice.ToString();
                this.textBox调整价格.ReadOnly = true;
            }
            else if (this.comboBox折扣.SelectedIndex == 1)
            {
                this.changePrice = 0 - this.finalPrice * 0.1;
                this.textBox调整价格.Text = this.changePrice.ToString();
                this.textBox调整价格.ReadOnly = true;
            }
        }

        private void 订单预览ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            String orderId = FunctionHelper.GetgridViewValue(this.gridView历史订单, this.gridView历史订单.FocusedRowHandle, "orderId");
            new Form订单预览新(orderId).ShowDialog();
        }

        private void simpleButton维护客户地址_Click(object sender, EventArgs e)
        {
            if (String.IsNullOrEmpty(this.mobile))
            {
                MessageBox.Show("请选择要维护地址的客户");
                return;
            }
            new FormMTO添加客户地址(this.mobile).ShowDialog();
            this.手机号查找信息并赋值(this.mobile);
        }

        private void simpleButton查看定制尺寸表_Click(object sender, EventArgs e)
        {
            if (!String.IsNullOrWhiteSpace(this.textBox定制款式名称.Text))
            {
                new Form下单时仅查看尺寸表(this.textBox定制款式名称.Text.Trim()).ShowDialog();
            }
        }

        private void simpleButton查看客套尺寸表_Click(object sender, EventArgs e)
        {
            if (!String.IsNullOrWhiteSpace(this.textBox客套款式名称.Text))
            {
                new Form下单时仅查看尺寸表(this.textBox客套款式名称.Text.Trim()).ShowDialog();
            }
        }

        private void simpleButton打印销售订单_Click(object sender, EventArgs e)
        {
            XtraReport销售订单 report = new XtraReport销售订单(customerSaleOrderReportDTO);
            //  循环取details并清洗尺寸
            report.DataSource = this.customerSaleOrderReportDTO.customerSaleOrderReportDetailDTOList;
            ReportPrintTool tool = new ReportPrintTool(report);
            tool.ShowPreview();
        }
    }
    public class VerificationVO
    {
        public String mobile { get; set; }
        public String storeId { get; set; }
        public String storeName { get; set; }
        public String assistantId { get; set; }
        public String assistantName { get; set; }
        public String salesId { get; set; }
        public String salesName { get; set; }
        public String assistantMnemonic { get; set; }
        public VerificationVO()
        {

        }
        public VerificationVO buildMobile(String mobile)
        {
            this.mobile = mobile;
            return this;
        }
        public VerificationVO buildStore(String storeId, String storeName)
        {
            this.storeId = storeId;
            this.storeName = storeName;
            return this;
        }
        public VerificationVO buildSales(String salesId, String salesName)
        {
            this.salesId = salesId;
            this.salesName = salesName;
            return this;
        }
        public VerificationVO buildAssistant(String assistantId, String assistantName, String assistantMnemonic)
        {
            this.assistantId = assistantId;
            this.assistantName = assistantName;
            this.assistantMnemonic = assistantMnemonic;
            return this;
        }
        public Boolean build判空()
        {
            if (String.IsNullOrEmpty(this.storeId)
                || String.IsNullOrEmpty(this.assistantId))
            {
                return false;
            }
            else
            {
                return true;
            }
        }

        public void clearStore()
        {
            this.storeId = "";
            this.storeName = "";
        }
    }

    public class Model整合下单
    {
        //店铺
        public List<DTO销售表头> saleStores = new List<DTO销售表头>();
        //销售员
        public List<SalesAssistantDTO> salesAssistants = new List<SalesAssistantDTO>();
        //全部登记样衣
        public List<SaleStyleSample> saleStyleSamples = new List<SaleStyleSample>();
        //可选面料
        public List<面料选择> allMaterials = new List<面料选择>();
        // 电话、店铺、销售员判断VO
        public VerificationVO verificationVO = new VerificationVO();
        // 客户整体调价
        public CustomerDailyDiscountDTO customerDailyDiscountDTO = new CustomerDailyDiscountDTO();
        //客户地址信息
        public CustomerPDTO customerPDTO = new CustomerPDTO();
        public String customerAddress { get; set; }
        // 客户当天定制和客套销售确认单
        public List<SaleConfirmQueryTitileDTO> saleConfirmQueryTitileDTOs = new List<SaleConfirmQueryTitileDTO>();
        // 客户历史订单
        public List<OrderCommitDTO返回> historicalOrders = new List<OrderCommitDTO返回>();
        //现货
        private String saleSessionId { get; set; }
        private StockInOutDetailDTO saleStockInOutDetailDTO = new StockInOutDetailDTO();
        private List<StockInOutDetailDTO> saleStockInOutDetailDTOs = new List<StockInOutDetailDTO>();
        private StockInOutTitleDTO saleStockInOutTitleDTO = new StockInOutTitleDTO();


        public Model整合下单()
        {
            //  下单选择店铺
            this.saleStores = 销售记录Service.get店铺();
            this.salesAssistants = 销售确认Service.get销售员带助记码();
            this.saleStyleSamples = 货号管理Service.getSaleStyleSampleWithDateTime(0, 5000);
            this.allMaterials = MTO订单Service.getMaterialOrderIndexAll();
        }
        public Model整合下单 build客户销售确认()
        {
            this.saleConfirmQueryTitileDTOs = 销售确认Service.getDaySaleConfirmListWithBalanceByMobile(this.verificationVO.mobile).saleConfirmQueryTitileDTOS;
            return this;
        }
        public Model整合下单 build客户信息(String mobile)
        {
            this.verificationVO.buildMobile(mobile);
            this.customerPDTO = CRM客户Service.getCustomerPByMobile(mobile);
            this.customerAddress =
                this.customerPDTO.addressProvince
                + this.customerPDTO.addressCity
                + this.customerPDTO.addressDistrict
                + this.customerPDTO.addressDetail;
            this.historicalOrders = 订单预览新Service.getOrderCommitsByMoblie(mobile);
            return this;
        }

        #region 现货销售
        //public Model整合下单 getPreStockInOutDetailByBarcode(String saleBarcode)
        //{
        //    //  预出库
        //    this.saleStockInOutDetailDTO =
        //            成品出库单Service.preStockInOutDetailWithCustomerInfoByBarcode(
        //            this.saleSessionId,
        //            saleBarcode,
        //            0,
        //            StockInOutTypeConst.ShopSaleOut,
        //            this.verificationVO.storeId
        //            );
        //    try { this.saleStockInOutDetailDTO.styleSizeCd = this.saleStockInOutDetailDTO.styleSizeCd.Replace("IGS_GROUP_SIZE-", "").Replace("EGS_GROUP_SIZE-", ""); } catch { }
        //    if (!String.IsNullOrEmpty(this.saleStockInOutDetailDTO.barcode))
        //    {
        //        if (this.saleStockInOutDetailDTOs.Count > 0)
        //        {
        //            if (!this.saleStockInOutDetailDTOs.Exists(dto => dto.barcode.Equals(this.saleStockInOutDetailDTO.barcode)))
        //            {
        //                this.saleStockInOutDetailDTOs.Add(this.saleStockInOutDetailDTO);
        //            }
        //        }
        //        else
        //        {
        //            this.saleStockInOutDetailDTOs.Add(this.saleStockInOutDetailDTO);
        //        }
        //    }
        //    return this;
        //}
        //public Model整合下单 saveStockSaleOut()
        //{
        //    if (this.saleStockInOutDetailDTOs.Count > 0)
        //    {
        //        //  现货销售出库
        //        this.saleStockInOutTitleDTO =
        //            出入库Service.saveStockSaleOut(
        //                this.saleSessionId,
        //                this.verificationVO.storeId,
        //                this.verificationVO.storeName,
        //                this.verificationVO.assistantMnemonic,
        //                this.customerPDTO.customerName,
        //                "",
        //                this.verificationVO.mobile,
        //                this.customerAddress
        //                );
        //        //  提交销售确认
        //        try
        //        {
        //            //销售出库
        //            List<GarmentSaleConfirmDTO> garmentSaleConfirmDTOs = new List<GarmentSaleConfirmDTO>();
        //            List<GarmentSaleConfirmDTO> garmentSaleConfirmRequestDTOs = new List<GarmentSaleConfirmDTO>();
        //            foreach (StockInOutDetailDTO item in this.saleStockInOutDetailDTOs)
        //            {
        //                garmentSaleConfirmDTOs.Add(
        //                    new GarmentSaleConfirmDTO(this.verificationVO.mobile, item.barcode, this.verificationVO.storeId, this.verificationVO.assistantMnemonic));
        //                garmentSaleConfirmRequestDTOs.Add(
        //                    new GarmentSaleConfirmDTO(this.verificationVO.mobile, item.barcode, this.verificationVO.storeId, this.verificationVO.assistantId));
        //            }
        //            List<GarmentSaleConfirmDTO> 返回值garmentSaleConfirmDTOs = 销售确认Service.saveGarmentSaleConfirm(garmentSaleConfirmRequestDTOs);

        //            //保存成衣销售确认单
        //            //销售确认Service.saveGarmentSaleConfirm(garmentSaleConfirmRequestDTOs);
        //        }
        //        catch { }
        //        //
        //        this.saleSessionId = new FunctionHelper().Uuid;
        //        this.saleStockInOutDetailDTOs.Clear();
        //        this.saleStockInOutDetailDTO = new StockInOutDetailDTO();
        //    }
        //    return this;
        //}
        #endregion

    }
}

